//
//  LoginPasswordViewModel.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 12.04.25.
//

import Foundation
class LoginPasswordViewModel : ObservableObject {
    
    @Published var isLoading = false
    
    @Published var loginState: String = ""
    
    func login(phone: String, password: String) {
        isLoading = true
        let pwd = LoginUtils.encrypt(pwd: password)
        KoiAccountingNetApi.standard.loginPassword(phone: phone, password: pwd) { result in
            switch result {
            case .success(let user):
                // 保存登录信息
                KoiAccountingUserManager.standard.login(user: user)
                self.loginState = "success"
                self.isLoading = false
            case .failure(let error):
                self.isLoading = false
                logger.error("loginPassword fail \(error)")
            }
        }
    }
}
